home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / mlpmodul.sit / MacLogimoPlus Documentation / DEF3 Files / OStrings.DEF < prev    next >
Encoding:
Modula Definition  |  1990-06-14  |  5.2 KB  |  137 lines  |  [TEXT/PMED]

  1. DEFINITION MODULE OStrings; (* Franz Kronseder / 14.05.85 *)
  2.                             (* last modified 30.05.85 *)
  3. (* intended to supply a complete Set of String Manupulation Functions *)
  4. (* for the Strings in the Macintosh operating system format.          *)
  5.  
  6. FROM SYSTEM IMPORT ADDRESS,ADR;
  7. EXPORT QUALIFIED
  8.         OStr7,OStr15,OStr31,OStr63,OStr127,OStr255,RefOStr,
  9.         mkOStr,mkModStr,mkRef1,mkRef2,mkRefEmpty,
  10.         msg,msgln,msgat,msgXY,errmsg,
  11.         ReadOStr,askmsg,askmsgat,askmsgXY,WaitOK,askYesNo,
  12.         OStrLen,OStrCh,OStrPos,OStrPat,OStrEqual,OStrCopy,OStrConcat,
  13.         OStrOvWrStr,OStrInsCH,OStrDelCH,OStrInsStr,OStrDelStr;
  14.  
  15. (*** TYPE OString   = OPEN ARRAY OF CHAR ***)
  16. (*** TYPE ModString = OPEN ARRAY OF CHAR ***)
  17.  
  18. TYPE OStr7   = ARRAY[0..  7] OF CHAR;
  19.      OStr15  = ARRAY[0.. 15] OF CHAR;
  20.      OStr31  = ARRAY[0.. 31] OF CHAR;
  21.      OStr63  = ARRAY[0.. 63] OF CHAR;
  22.      OStr127 = ARRAY[0..127] OF CHAR;
  23.      OStr255 = ARRAY[0..255] OF CHAR;
  24.  
  25.      RefOStr = ADDRESS; (* reference to an OStr *)
  26.  
  27. (*----------------------------------------------------------*)
  28.  
  29. (**** here come procedures to convert between pascal ****)
  30. (**** and modula format                              ****)
  31. PROCEDURE mkOStr(VAR ModStr, OStr:ARRAY OF CHAR);
  32.  (* convert a Modula String to an OStr *)
  33.  
  34. PROCEDURE mkModStr(VAR  OStr,ModStr:ARRAY OF CHAR);
  35.  (* convert a OStr to a Modula String   *)
  36.  
  37. (**** here come procedures that return pointers to OStrings ****)
  38.  
  39. PROCEDURE mkRef1(VAR ModStr:ARRAY OF CHAR):RefOStr;
  40. PROCEDURE mkRef2(VAR ModStr:ARRAY OF CHAR):RefOStr;
  41.  
  42.  (* the functions mkRef1 and mkRef2 each take a Modula string as argument *)
  43.  (* and return a pointer to an equivalent OString.                        *)
  44.  (* every new call to mkRef1/mkRef2 destroys the previous contents of     *)
  45.  (* the corresponding OString.                                            *)
  46.  (* the arguments are not modified.                                       *)
  47.  (* the purpose of this procedures is to pass Modula-2 strings to         *)
  48.  (* toolbox procedures (at most 2 at a time)                              *)
  49.  (* Example:   SetWTitle (theWindow, mkRef1 ("MY WINDOW") );              *)
  50.  (* the strings can be 127 characters long.                               *)
  51.  
  52. PROCEDURE mkRefEmpty():RefOStr;
  53.  (* returns the address of the empty OString *)
  54.  
  55. (**** here come procedures to display  OStrings on the ****)
  56. (**** screen                                           ****)
  57.  
  58. PROCEDURE msg(msgPtr:RefOStr);
  59.  (* write the message, an OStr pointed to by msgPtr *)
  60.  
  61. PROCEDURE msgln(msgPtr:RefOStr);
  62.  (* writeln the message, an OStr pointed to by msgPtr *)
  63.  
  64. PROCEDURE msgat(h,v:INTEGER;msgPtr:RefOStr);
  65.  (* write the message at the position given in pixels *)
  66.  
  67. PROCEDURE msgXY(h,v:INTEGER;msgPtr:RefOStr);
  68.  (* write the message at the position given in chars *)
  69.  
  70. PROCEDURE errmsg(msgPtr:RefOStr;fatal:BOOLEAN);
  71.  (* tell User an Error Message; abort Program if fatal Flag *)
  72.  
  73. (*------------------------------------------------------------*)
  74. (** here come procedures for String Input from User **)
  75. PROCEDURE ReadOStr(msgPtr:RefOStr);
  76.  
  77. PROCEDURE askmsg(VAR prompt:ARRAY OF CHAR;msgPtr:RefOStr);
  78.  (* write prompt, read a string, writeln *)
  79.  (* ReadString a Pascalstring from the Console *)
  80.  
  81. PROCEDURE askmsgat(h,v:INTEGER;VAR prompt:ARRAY OF CHAR;msgPtr:RefOStr);
  82.  (* MoveTo, write prompt, readstring, writeln *)
  83.  
  84. PROCEDURE askmsgXY(h,v:INTEGER;VAR prompt:ARRAY OF CHAR;msgPtr:RefOStr);
  85.  (*ask the message at the position given in chars *)
  86.  
  87. PROCEDURE WaitOK;
  88.  (* wait until user types in a char at the console *)
  89.  
  90. PROCEDURE askYesNo(VAR prompt:ARRAY OF CHAR):BOOLEAN;
  91.  
  92. (*------------------------------------------------------------*)
  93. (* here come some functions about OStrings *)
  94. PROCEDURE OStrLen(msgPtr:RefOStr):CARDINAL;
  95.  (* returns the actual stringlength *)
  96.  
  97. PROCEDURE OStrCh(msgPtr:RefOStr;nth:CARDINAL):CHAR;
  98.  (* returns the nth char in that string *)
  99.  
  100. PROCEDURE OStrPos(msgPtr:RefOStr;ch:CHAR):CARDINAL;
  101.  (* returns the position of ch in that string, *)
  102.  (* zero if not found *)
  103.  
  104. PROCEDURE OStrPat(pattern:RefOStr; object:RefOStr):CARDINAL;
  105.  (* returns the position of the pattern string in the object string *)
  106.  
  107. PROCEDURE OStrEqual(s1,s2:RefOStr):BOOLEAN;
  108.  (* tests if both strings have same size and chars *)
  109.  
  110. PROCEDURE OStrCopy(src,dest:RefOStr):RefOStr;
  111.  (* copies OStrLen(src) chars from source to destination *)
  112.  
  113. PROCEDURE OStrConcat(src1,src2,dest:RefOStr):RefOStr;
  114.  (* places the concatenation of the two source-strings *)
  115.  (* at dest and returns a pointer to dest *)
  116. PROCEDURE OStrOvWrStr(dest,substring:RefOStr; pos:CARDINAL):RefOStr;
  117.  (* overwrite with substring *)
  118.  
  119. PROCEDURE OStrInsCH(dest:RefOStr;ch:CHAR;pos:CARDINAL):RefOStr;
  120.  (* Insert a char in the string at a given position *)
  121.  
  122. PROCEDURE OStrDelCH(dest:RefOStr;ch:CHAR;pos:CARDINAL):RefOStr;
  123.  (* Delete a char in the string at a given position *)
  124.  
  125. PROCEDURE OStrInsStr(dest,src:RefOStr;pos:CARDINAL):RefOStr;
  126.  (* Insert a substring at given position *)
  127.  
  128. PROCEDURE OStrDelStr(dest,src:RefOStr;pos:CARDINAL):RefOStr;
  129.  (* Delete a substring at given position *)
  130.  
  131.  
  132. END OStrings.
  133.  
  134. (* An OString (or sometimes called 'Pascal String') is an array of   *)
  135. (* char, maximum length 256 bytes, with ORD(byte 0) indicating the    *)
  136. (* actual string length *)
  137.